<?php
/**
* @version $Id: mod_login.php 7211 2007-04-29 02:26:51Z robs $
* @package Joomla
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

global $mosConfig_frontend_login;

if ( $mosConfig_frontend_login != NULL && ($mosConfig_frontend_login === 0 || $mosConfig_frontend_login === '0')) {
	return;
}

// url of current page that user will be returned to after login
if ($query_string = mosGetParam( $_SERVER, 'QUERY_STRING', '' )) {
	$return = 'index.php?' . $query_string;
} else {
	$return = 'index.php';
}

$registration_enabled 	= $mainframe->getCfg( 'allowUserRegistration' );
$message_login 			= $params->def( 'login_message', 	0 );
$message_logout 		= $params->def( 'logout_message', 	0 );
$login 					= $params->def( 'login', 			$return );
$logout 				= $params->def( 'logout', 			$return );
$name 					= $params->def( 'name', 			1 );
$greeting 				= $params->def( 'greeting', 		1 );
$pretext 				= $params->get( 'pretext' );
$posttext 				= $params->get( 'posttext' );
?>
<div class="box">
	<div class="title">
		<div class="left"></div>
		<div class="center">Góc thành viên</div>
		<div class="right"></div>
	</div>
	<div class="boxContent">
	<?php
	if ( $my->id ) {
	// Logout output
	// ie HTML when already logged in and trying to logout
		if ( $name ) {
			$name = $my->name;
		} else {
			$name = $my->username;
		}
		?>
		<form action="<?php echo sefRelToAbs( 'index.php?option=logout' ); ?>" method="post" name="logout">
		<?php
		if ( $greeting ) {	
			?>			
			<table border="0" cellpadding="0" cellspacing="5" width="90%" align="center">
				<tr>
					<td align="left">Xin chào, <b><?php echo $name;?></b></td>
				</tr>
				<!--
				<tr>				
					<td valign="top" align="left">
					<a href="index.php?option=com_user&task=UserDetails" class="user">Quản lý thông tin cá nhân</a>
					</td>
				</tr>
				<tr>				
					<td valign="top" align="left">
					<a href="<?php echo $mosConfig_live_site;?>/index.php?option=com_bds&task=post">Đăng tin bất động sản</a>
					</td>
				</tr>
				<tr>				
					<td valign="top" align="left">
					<?php
					$sql = "select COUNT(*) FROM #__bds WHERE user_id=".$my->id;
					$database->setQuery($sql);
					$total = $database->loadResult();
					?>
					<a href="<?php echo $mosConfig_live_site;?>/index.php?option=com_bds&task=list">Quản lý tin đã đăng <b>(<?php echo $total;?>)</b></a>
					</td>
				</tr>
				<tr>				
					<td valign="top" align="left">
					<a href="<?php echo $mosConfig_live_site;?>/index.php?option=com_order&task=posthd">Đăng câu hỏi đáp</a>
					</td>
				</tr>
				 -->
				<tr>
					<td valign="top" align="left">
						<input type="submit" name="Submit" class="button" value="Thoát" />			
						<input type="hidden" name="option" value="logout" />
						<input type="hidden" name="op2" value="logout" />
						<input type="hidden" name="lang" value="<?php echo $mosConfig_lang; ?>" />
						<input type="hidden" name="return" value="<?php echo htmlspecialchars( sefRelToAbs( $logout ) ); ?>" />
						<input type="hidden" name="message" value="<?php echo htmlspecialchars( $message_logout ); ?>" />
					</td>
				</tr>
			</table>			
			<?php
		}
		?>
		</form>
		<?php
	} else {
	// Login output
	// ie HTML when not logged in and trying to login
		// used for spoof hardening
		$validate = josSpoofValue(1);
		?>
		<form action="<?php echo sefRelToAbs( 'index.php' ); ?>" method="post" name="login" >
		<?php
		echo $pretext;
		?>
			<table border="0" cellpadding="0" cellspacing="5" width="90%" align="center">
				<tr>
					<td align="left"><b>Tên đăng nhập :</b></td>
				</tr>
				<tr>
					<td align="left">
						<input name="username" id="mod_login_username" type="text" class="inputbox" alt="username" size="20" onfocus="if(this.value=='Tên đăng nhập') this.value='';" onblur="if(this.value=='') this.value='Tên đăng nhập';" value="Tên đăng nhập" size="20" />
					</td>
				</tr>
				<tr>
					<td align="left"><b>Mật khẩu :</b></td>
				</tr>
				<tr>
					<td align="left">
						<input type="password" id="mod_login_password" name="passwd" class="inputbox" size="20" alt="password" onfocus="if(this.value=='Mật khẩu') this.value='';" onblur="if(this.value=='') this.value='Mật khẩu';" value="Mật khẩu" />
					</td>
				</tr>
				<tr>
					<td align="left"><input type="submit" name="Submit" class="button" value="Đăng nhập" /></td>
				</tr>
				<tr>
					<td align="left">
						<a href="<?php echo sefRelToAbs( 'index.php?option=com_registration&task=lostPassword' ); ?>">Quên mật khẩu ?</a>
					</td>
				</tr>
				<tr>
					<td align="left">
						<a href="<?php echo sefRelToAbs( 'index.php?option=com_registration&task=register' ); ?>">Đăng ký thành viên</a>
					</td>
				</tr>
			</table>
		<?php
		echo $posttext;
		?>
	
		<input type="hidden" name="option" value="login" />
		<input type="hidden" name="op2" value="login" />
		<input type="hidden" name="lang" value="<?php echo $mosConfig_lang; ?>" />
		<input type="hidden" name="return" value="<?php echo htmlspecialchars( sefRelToAbs( $login ) ); ?>" />
		<input type="hidden" name="message" value="<?php echo htmlspecialchars( $message_login ); ?>" />
		<input type="hidden" name="force_session" value="1" />
		<input type="hidden" name="<?php echo $validate; ?>" value="1" />
		</form>
		<?php
	}
	?>
	</div>
</div>
